import os
import time
import unittest

from XTestRunner import HTMLTestRunner
from base import log
from config import BASE_PATH

if __name__ == "__main__":
    # 套件
    suite = unittest.TestLoader().discover(BASE_PATH + os.sep + "script", "test_app_sniffing.py")
    # 执行并生成测试报告
    file_path = BASE_PATH + os.sep + "report" + os.sep + "ok_browser_sniffing_{}.html".format(
        time.strftime("%Y%m%d%H%M%S"))
    log.info("OkBrowser浏览嗅探测试报告正在生成......")
    with(open(file_path, "wb")) as fp:
        runner = HTMLTestRunner(
            stream=fp,
            title="<project name>OkBrowser浏览嗅探测试报告",
            description="OkBrowser浏览嗅探 1.0.0 by曾伟雄",
            language="zh-CN",
            # rerun=1  # 容错机制重试1次
        )
        runner.run(suite)
    log.info("OkBrowser浏览嗅探执行成功并生成报告:{}".format(file_path))

